package com.yc.backstage.controller;

import com.yc.backstage.entity.SysMenu;
import com.yc.backstage.service.SysMenuService;
import com.yc.backstage.utils.SecurityUtils;
import com.yc.common.res.ResultClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Classname SysMenuController
* @Description
* @Version 1.0.0
* @Date 2022-08-23 11:49:19
* @Created by Mikechen
*/
@RestController
@RequestMapping("/backstage/sysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;
    /**
     * 加载对应角色菜单列表树
     */
    @GetMapping(value = "/roleMenuTreeselect/{roleId}")
    public ResultClass roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
        List<SysMenu> menus = sysMenuService.selectMenuList(SecurityUtils.getUserId());
        Map<String,Object> map=new HashMap<>();
        map.put("checkedKeys", sysMenuService.selectMenuListByRoleId(roleId));
        map.put("menus", sysMenuService.buildMenuTreeSelect(menus));
        return ResultClass.success(map);
    }
}
